/*
 * @Author: your name
 * @Date: 2022-02-28 23:33:51
 * @LastEditTime: 2022-02-28 23:46:59
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \the-way-of-interview\array.js
 */

// 2. toString & split
function flatten(arr){
    return arr.toString().split(',').map((item) =>{
        return Number(item);
    })
}

console.log(flatten([1,2,3,[2,3,4],5]))

// 3. join & split
function flatten1(arr) {
    return arr.join(',').split(',').map((item) =>{
        return Number(item);
    })
}
console.log(flatten([1,2,3,[2,3,4],5,6]))

// 5. 扩展运算符
function flatten2(arr) {
    while (arr.some(item =>Array.isArray(item))){
        arr = [].concat(...arr)
    }
    return arr;
}

function dedupe(arr) {
    return Array.from(new Set(arr))
}
console.log(dedupe([1,1,2,3])) //[1,2,3]


